/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * InterfaceAdmin.java
 *
 * Created on 04/07/2010, 15:15:06
 */

package imobiliaria.gui;

import imobiliaria.controladores.ControladorAlugueis;
import imobiliaria.controladores.ControladorLogin;
import imobiliaria.controladores.ControladorPedidos;
import imobiliaria.controladores.ControladorTransacoes;
import imobiliaria.entidades.Aluguel;
import imobiliaria.entidades.FolhaDePagamento;
import imobiliaria.entidades.Login;
import imobiliaria.entidades.Pedido;
import imobiliaria.entidades.Sistema;
import imobiliaria.exceptions.ValorInvalidoException;
import javax.swing.JOptionPane;

/**
 *
 * @author Convidado
 */
public class InterfaceAdmin extends javax.swing.JFrame implements InterfaceOpIF {

    private Sistema sis = new Sistema();

    /** Creates new form InterfaceAdmin */
    public InterfaceAdmin() {

        try {
        	sis.atualizaDados();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Erro:\n" + e.getMessage(),
                    "Erro ao Atualizar Dados", JOptionPane.ERROR_MESSAGE);

        }

        initComponents();

        setLocationRelativeTo(null);

        atualiza();


    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        JL_SaldoAtualCaixa = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        JL_DataUltimoPagamento = new javax.swing.JLabel();
        JB_VerFolhaDePagamento = new javax.swing.JButton();
        JL_Pagamento = new javax.swing.JLabel();
        JB_ListaTransacoes = new javax.swing.JButton();
        JB_ListaTransacoesMensais = new javax.swing.JButton();
        JB_EfetuaPagamento = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        JCB_Logins = new javax.swing.JComboBox();
        JL_NumTotalLogins = new javax.swing.JLabel();
        JB_InfoLogin = new javax.swing.JButton();
        jPanel6 = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        JB_ListaPedidos = new javax.swing.JButton();
        JCB_Alugueis = new javax.swing.JComboBox();
        JB_VerInfoAluguel = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        JB_ExcluirPedido = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        JB_VerInfoPedido = new javax.swing.JButton();
        JB_EfetuarPedido = new javax.swing.JButton();
        JCB_Pedidos = new javax.swing.JComboBox();
        JB_ListaAlugueis = new javax.swing.JButton();
        JB_CancelarAluguel = new javax.swing.JButton();
        JB_MenuImoveis = new javax.swing.JButton();
        JB_MenuClientes = new javax.swing.JButton();
        JB_MenuFuncionarios = new javax.swing.JButton();
        JL_NumTotalPedidos = new javax.swing.JLabel();
        JL_NumTotalAlugueis = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jLabel3 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        JTF_Salario = new javax.swing.JTextField();
        JTF_Comissao = new javax.swing.JTextField();
        JB_SalvarSalario = new javax.swing.JButton();
        JB_Desloga = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(800, 580));
        setResizable(false);
        getContentPane().setLayout(null);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel1.setText("Menu de Administração");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(10, 10, 510, 30);

        jLabel2.setText("Bem Vindo!");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(10, 40, 560, 15);

        JL_SaldoAtualCaixa.setText("Saldo Atual do Caixa: 00,00");
        getContentPane().add(JL_SaldoAtualCaixa);
        JL_SaldoAtualCaixa.setBounds(10, 540, 260, 15);

        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imobiliaria/images/iMobLogo.png"))); // NOI18N
        getContentPane().add(jLabel6);
        jLabel6.setBounds(510, 10, 250, 200);

        jPanel4.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel4.setLayout(null);

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel11.setText("Financeiro");
        jPanel4.add(jLabel11);
        jLabel11.setBounds(10, 10, 90, 16);

        JL_DataUltimoPagamento.setText("Ultimo Pagamento Efetuado: XX/XX/XXXX");
        jPanel4.add(JL_DataUltimoPagamento);
        JL_DataUltimoPagamento.setBounds(10, 30, 450, 15);

        JB_VerFolhaDePagamento.setText("Ver Folha de Pagamento");
        JB_VerFolhaDePagamento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_VerFolhaDePagamentoActionPerformed(evt);
            }
        });
        jPanel4.add(JB_VerFolhaDePagamento);
        JB_VerFolhaDePagamento.setBounds(10, 90, 220, 31);
        jPanel4.add(JL_Pagamento);
        JL_Pagamento.setBounds(430, 10, 40, 30);

        JB_ListaTransacoes.setText("Lista Transacoes");
        JB_ListaTransacoes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_ListaTransacoesActionPerformed(evt);
            }
        });
        jPanel4.add(JB_ListaTransacoes);
        JB_ListaTransacoes.setBounds(240, 60, 210, 31);

        JB_ListaTransacoesMensais.setText("Lista Transacoes Mensais");
        JB_ListaTransacoesMensais.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_ListaTransacoesMensaisActionPerformed(evt);
            }
        });
        jPanel4.add(JB_ListaTransacoesMensais);
        JB_ListaTransacoesMensais.setBounds(10, 60, 220, 31);

        JB_EfetuaPagamento.setText("Efetua Pagamento");
        JB_EfetuaPagamento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_EfetuaPagamentoActionPerformed(evt);
            }
        });
        jPanel4.add(JB_EfetuaPagamento);
        JB_EfetuaPagamento.setBounds(240, 90, 210, 31);

        getContentPane().add(jPanel4);
        jPanel4.setBounds(10, 130, 470, 130);

        jPanel5.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel5.setLayout(null);

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel5.setText("Logins do Sistema");
        jPanel5.add(jLabel5);
        jLabel5.setBounds(10, 10, 240, 16);

        JCB_Logins.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Login1", "Login2", "Login3", "Login4" }));
        jPanel5.add(JCB_Logins);
        JCB_Logins.setBounds(10, 80, 240, 25);

        JL_NumTotalLogins.setText("Numero Total de Logins: XX");
        jPanel5.add(JL_NumTotalLogins);
        JL_NumTotalLogins.setBounds(10, 50, 220, 15);

        JB_InfoLogin.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imobiliaria/images/info2icon.png"))); // NOI18N
        JB_InfoLogin.setText("Info");
        JB_InfoLogin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_InfoLoginActionPerformed(evt);
            }
        });
        jPanel5.add(JB_InfoLogin);
        JB_InfoLogin.setBounds(10, 120, 240, 40);

        getContentPane().add(jPanel5);
        jPanel5.setBounds(500, 360, 260, 170);

        jPanel6.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel6.setLayout(null);

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel10.setText("Alugueis e Pedidos");
        jPanel6.add(jLabel10);
        jLabel10.setBounds(10, 10, 190, 16);

        JB_ListaPedidos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imobiliaria/images/noteIcon.png"))); // NOI18N
        JB_ListaPedidos.setText("Listar Pedidos");
        JB_ListaPedidos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_ListaPedidosActionPerformed(evt);
            }
        });
        jPanel6.add(JB_ListaPedidos);
        JB_ListaPedidos.setBounds(270, 10, 190, 30);

        JCB_Alugueis.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "InfoPedido1", "InfoPedido2", "InfoPedido3" }));
        jPanel6.add(JCB_Alugueis);
        JCB_Alugueis.setBounds(10, 170, 450, 25);

        JB_VerInfoAluguel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imobiliaria/images/info2icon.png"))); // NOI18N
        JB_VerInfoAluguel.setText("Info");
        JB_VerInfoAluguel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_VerInfoAluguelActionPerformed(evt);
            }
        });
        jPanel6.add(JB_VerInfoAluguel);
        JB_VerInfoAluguel.setBounds(180, 200, 140, 40);

        jLabel4.setText("Informacoes de Alugueis: ");
        jPanel6.add(jLabel4);
        jLabel4.setBounds(10, 150, 260, 15);

        JB_ExcluirPedido.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imobiliaria/images/exitIcon.png"))); // NOI18N
        JB_ExcluirPedido.setText("Excluir");
        JB_ExcluirPedido.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_ExcluirPedidoActionPerformed(evt);
            }
        });
        jPanel6.add(JB_ExcluirPedido);
        JB_ExcluirPedido.setBounds(330, 90, 130, 40);

        jLabel9.setText("Efetuar Pedidos:");
        jPanel6.add(jLabel9);
        jLabel9.setBounds(10, 40, 140, 15);

        JB_VerInfoPedido.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imobiliaria/images/info2icon.png"))); // NOI18N
        JB_VerInfoPedido.setText("Info");
        JB_VerInfoPedido.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_VerInfoPedidoActionPerformed(evt);
            }
        });
        jPanel6.add(JB_VerInfoPedido);
        JB_VerInfoPedido.setBounds(180, 90, 140, 40);

        JB_EfetuarPedido.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imobiliaria/images/okIcon.png"))); // NOI18N
        JB_EfetuarPedido.setText("Efetuar");
        JB_EfetuarPedido.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_EfetuarPedidoActionPerformed(evt);
            }
        });
        jPanel6.add(JB_EfetuarPedido);
        JB_EfetuarPedido.setBounds(10, 90, 160, 40);

        JCB_Pedidos.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "InfoPedido1", "InfoPedido2", "InfoPedido3" }));
        jPanel6.add(JCB_Pedidos);
        JCB_Pedidos.setBounds(10, 60, 450, 25);

        JB_ListaAlugueis.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imobiliaria/images/noteIcon.png"))); // NOI18N
        JB_ListaAlugueis.setText("Lista Alugueis");
        JB_ListaAlugueis.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_ListaAlugueisActionPerformed(evt);
            }
        });
        jPanel6.add(JB_ListaAlugueis);
        JB_ListaAlugueis.setBounds(10, 200, 160, 40);

        JB_CancelarAluguel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imobiliaria/images/exitIcon.png"))); // NOI18N
        JB_CancelarAluguel.setText("Cancelar");
        JB_CancelarAluguel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_CancelarAluguelActionPerformed(evt);
            }
        });
        jPanel6.add(JB_CancelarAluguel);
        JB_CancelarAluguel.setBounds(330, 200, 130, 40);

        getContentPane().add(jPanel6);
        jPanel6.setBounds(10, 280, 470, 250);

        JB_MenuImoveis.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imobiliaria/images/homeIcon.png"))); // NOI18N
        JB_MenuImoveis.setText("Imoveis");
        JB_MenuImoveis.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_MenuImoveisActionPerformed(evt);
            }
        });
        getContentPane().add(JB_MenuImoveis);
        JB_MenuImoveis.setBounds(330, 70, 150, 40);

        JB_MenuClientes.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imobiliaria/images/loginIcon.png"))); // NOI18N
        JB_MenuClientes.setText("Clientes");
        JB_MenuClientes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_MenuClientesActionPerformed(evt);
            }
        });
        getContentPane().add(JB_MenuClientes);
        JB_MenuClientes.setBounds(10, 70, 140, 40);

        JB_MenuFuncionarios.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imobiliaria/images/pedidoIcon.png"))); // NOI18N
        JB_MenuFuncionarios.setText("Funcionarios");
        JB_MenuFuncionarios.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_MenuFuncionariosActionPerformed(evt);
            }
        });
        getContentPane().add(JB_MenuFuncionarios);
        JB_MenuFuncionarios.setBounds(160, 70, 160, 40);

        JL_NumTotalPedidos.setText("Numero Total de Pedidos: XX");
        getContentPane().add(JL_NumTotalPedidos);
        JL_NumTotalPedidos.setBounds(500, 300, 260, 15);

        JL_NumTotalAlugueis.setText("Numero Total de Alugueis: XX");
        getContentPane().add(JL_NumTotalAlugueis);
        JL_NumTotalAlugueis.setBounds(500, 320, 260, 15);
        getContentPane().add(jScrollPane1);
        jScrollPane1.setBounds(560, 480, 2, 2);

        jLabel3.setText("Salario Atual: (R$)");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(500, 200, 150, 15);

        jLabel7.setText("Comissao: (%)");
        getContentPane().add(jLabel7);
        jLabel7.setBounds(500, 230, 150, 15);
        getContentPane().add(JTF_Salario);
        JTF_Salario.setBounds(650, 200, 100, 25);
        getContentPane().add(JTF_Comissao);
        JTF_Comissao.setBounds(650, 230, 100, 25);

        JB_SalvarSalario.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imobiliaria/images/saveIcon.png"))); // NOI18N
        JB_SalvarSalario.setText("Salvar");
        JB_SalvarSalario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_SalvarSalarioActionPerformed(evt);
            }
        });
        getContentPane().add(JB_SalvarSalario);
        JB_SalvarSalario.setBounds(500, 260, 110, 37);

        JB_Desloga.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imobiliaria/images/backIcon.png"))); // NOI18N
        JB_Desloga.setText("Deslogar");
        JB_Desloga.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_DeslogaActionPerformed(evt);
            }
        });
        getContentPane().add(JB_Desloga);
        JB_Desloga.setBounds(620, 260, 130, 30);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void JB_VerFolhaDePagamentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_VerFolhaDePagamentoActionPerformed
        
        
        FolhaDePagamento folha = ControladorTransacoes.getInstance()
                .getUltimaFolhaDePagamento();
        
        if (folha == null) {
            JOptionPane.showMessageDialog(null, "Nenhum pagamento efetuado",
                    "Folha de Pagamento", JOptionPane.INFORMATION_MESSAGE);
            return;
        }

        new InterfaceListagem("Folha de Pagamento", "Ultima Folha de Pagamento",
                ControladorTransacoes.getInstance().getUltimaFolhaDePagamento()
                .getFolhaDePagamentoString()).setVisible(true);
    }//GEN-LAST:event_JB_VerFolhaDePagamentoActionPerformed

    private void JB_MenuImoveisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_MenuImoveisActionPerformed
        new InterfaceOpImovel().setVisible(true);
    }//GEN-LAST:event_JB_MenuImoveisActionPerformed

    private void JB_MenuClientesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_MenuClientesActionPerformed
        new InterfaceOpClientes().setVisible(true);
    }//GEN-LAST:event_JB_MenuClientesActionPerformed

    private void JB_MenuFuncionariosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_MenuFuncionariosActionPerformed
        new InterfaceOpFuncionario(this).setVisible(true);
    }//GEN-LAST:event_JB_MenuFuncionariosActionPerformed

    private void JB_ListaTransacoesMensaisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_ListaTransacoesMensaisActionPerformed
        new InterfaceListagem("Transacoes", "Listagem de Transacoes Mensais",
                ControladorTransacoes.getInstance().listaTransacoesMensais())
                .setVisible(true);
    }//GEN-LAST:event_JB_ListaTransacoesMensaisActionPerformed

    private void JB_ListaPedidosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_ListaPedidosActionPerformed
        new InterfaceListagem("Pedidos", "Listagem de Pedidos", ControladorPedidos.getInstance()
                .listagemDePedido()).setVisible(true);
    }//GEN-LAST:event_JB_ListaPedidosActionPerformed

    private void JB_ListaTransacoesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_ListaTransacoesActionPerformed
        new InterfaceListagem("Transacoes", "Listagem de Transacoes",
                ControladorTransacoes.getInstance().listaTransacoes())
                .setVisible(true);
    }//GEN-LAST:event_JB_ListaTransacoesActionPerformed

    private void JB_EfetuaPagamentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_EfetuaPagamentoActionPerformed

        try {
        FolhaDePagamento folha = ControladorTransacoes.getInstance().
                efetuaPagamentoNoMes();

        new InterfaceListagem("Folha de Pagamento", "Ultima Folha de Pagamento",
                folha.getFolhaDePagamentoString()).setVisible(true);

        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Erro ao Efetuar Pagamento:\n\n"
                    + e.getMessage(),
                    "Pagamento", JOptionPane.ERROR_MESSAGE);
        }
        atualiza();
    }//GEN-LAST:event_JB_EfetuaPagamentoActionPerformed

    private void JB_ListaAlugueisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_ListaAlugueisActionPerformed
        new InterfaceListagem("Alugueis", "Listagem de Alugueis", ControladorAlugueis.getInstance()
                .listaAlugueis()).setVisible(true);
    }//GEN-LAST:event_JB_ListaAlugueisActionPerformed

    private void JB_VerInfoAluguelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_VerInfoAluguelActionPerformed
        if (JCB_Alugueis.getSelectedItem() == null) {
            JOptionPane.showMessageDialog(null, "Nenhum Aluguel Selecionado",
                    "Aluguel", JOptionPane.ERROR_MESSAGE);
            return;

        }

        JOptionPane.showMessageDialog(null, "Informacao do Aluguel:\n\n" +
                ((Aluguel) JCB_Alugueis.getSelectedItem()).exibeInformacao(),
                    "Aluguel", JOptionPane.INFORMATION_MESSAGE);
    }//GEN-LAST:event_JB_VerInfoAluguelActionPerformed

    private void JB_VerInfoPedidoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_VerInfoPedidoActionPerformed
        if (JCB_Pedidos.getSelectedItem() == null) {
            JOptionPane.showMessageDialog(null, "Nenhum Pedido Selecionado",
                    "Pedido", JOptionPane.ERROR_MESSAGE);
            return;
        }

        JOptionPane.showMessageDialog(null, "Informacao do Pedido:\n\n" +
                ((Pedido) JCB_Pedidos.getSelectedItem()).exibeInformacao(),
                    "Pedido", JOptionPane.INFORMATION_MESSAGE);
    }//GEN-LAST:event_JB_VerInfoPedidoActionPerformed

    private void JB_CancelarAluguelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_CancelarAluguelActionPerformed
        if (JCB_Alugueis.getSelectedItem() == null) {
            JOptionPane.showMessageDialog(null, "Nenhum Aluguel Selecionado",
                    "Aluguel", JOptionPane.ERROR_MESSAGE);
            return;
        }

        if (ControladorAlugueis.getInstance().removeAluguel(
                ((Aluguel) JCB_Alugueis.getSelectedItem()).getImovel()
                .getRegistroImovel() + "")) {

            JOptionPane.showMessageDialog(null, "Aluguel Removido com Sucesso",
                    "Aluguel", JOptionPane.INFORMATION_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(null, "Erro ao remover Aluguel",
                    "Aluguel", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_JB_CancelarAluguelActionPerformed

    private void JB_ExcluirPedidoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_ExcluirPedidoActionPerformed
        if (JCB_Pedidos.getSelectedItem() == null) {
            JOptionPane.showMessageDialog(null, "Nenhum Pedido Selecionado",
                    "Pedido", JOptionPane.ERROR_MESSAGE);
            return;
        }

        try {
        ControladorPedidos.getInstance().removePedido(
                ((Pedido) JCB_Pedidos.getSelectedItem()).getImovel()
                .getRegistroImovel() + "");
        sis.salvarDados();
        atualiza();
            JOptionPane.showMessageDialog(null, "Pedido Removido com Sucesso",
                    "Pedido", JOptionPane.INFORMATION_MESSAGE);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Erro ao excluir Pedido:\n" +
                    e.getMessage(), "Pedido", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_JB_ExcluirPedidoActionPerformed

    private void JB_InfoLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_InfoLoginActionPerformed



        Login login = ControladorLogin.getInstance().getLogin(
                String.valueOf(JCB_Logins.getSelectedItem()));

        JOptionPane.showMessageDialog(null, "Informacoes do Login:\n\n" +
                "Username: " + login.getUserName() +
                "\nTipo de Login: " + login.getTipoLogin(),
                    "Login", JOptionPane.INFORMATION_MESSAGE);
    }//GEN-LAST:event_JB_InfoLoginActionPerformed

    private void JB_SalvarSalarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_SalvarSalarioActionPerformed

        double novoSalario;
        double novaComissao;

        try {

            novoSalario = Double.parseDouble(JTF_Salario.getText());
            novaComissao = Double.parseDouble(JTF_Comissao.getText())/100;

            if (novoSalario < 0 || novaComissao < 0) {
                throw new ValorInvalidoException("Valor Invalido");
            }


            ControladorTransacoes.getInstance().setComissao(novaComissao);
            ControladorTransacoes.getInstance().setSalario(novoSalario);

            JOptionPane.showMessageDialog(null, "Dados salvos com sucesso!",
                    "Salario e Comissao", JOptionPane.INFORMATION_MESSAGE);
        } catch (ValorInvalidoException e) {
            JOptionPane.showMessageDialog(null, "Valores nao podem ser negativos",
                    "Salario e Comissao", JOptionPane.ERROR_MESSAGE);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Valores Invalidos",
                    "Salario e Comissao", JOptionPane.ERROR_MESSAGE);
        }

        atualiza();


    }//GEN-LAST:event_JB_SalvarSalarioActionPerformed

    private void JB_EfetuarPedidoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_EfetuarPedidoActionPerformed
        if (JCB_Pedidos.getSelectedItem() == null) {
            JOptionPane.showMessageDialog(null, "Nenhum Pedido Selecionado",
                    "Efetuar Pedido", JOptionPane.ERROR_MESSAGE);
            return;
        }
        Pedido pedido = (Pedido) JCB_Pedidos.getSelectedItem();

        new InterfaceRecebeCreci(pedido, this).setVisible(true);
    }//GEN-LAST:event_JB_EfetuarPedidoActionPerformed

    private void JB_DeslogaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_DeslogaActionPerformed
        new TelaPrincipal().setVisible(true);
        dispose();
    }//GEN-LAST:event_JB_DeslogaActionPerformed


    private void preencheCBox() {

        JCB_Alugueis.removeAllItems();
        for (Aluguel a : ControladorAlugueis.getInstance().getListaAlugueis())
            JCB_Alugueis.addItem(a);

        JCB_Logins.removeAllItems();

        for (String loginInfo : ControladorLogin.getInstance().getListaLogins())
            JCB_Logins.addItem(loginInfo);

        JCB_Pedidos.removeAllItems();
        for (Pedido p : ControladorPedidos.getInstance().getListaPedidos())
            JCB_Pedidos.addItem(p);

        
    }

    public void atualiza() {

        preencheCBox();

        JTF_Salario.setText(ControladorTransacoes.getInstance().getSalario() + "");
        JTF_Comissao.setText((ControladorTransacoes.getInstance().getComissao()*100) + "");

        if (ControladorTransacoes.getInstance().pagouNesseMes()) {
            JL_Pagamento.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imobiliaria/images/okIcon.png")));
        } else {
            JL_Pagamento.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imobiliaria/images/exitIcon.png")));
        }

        JL_DataUltimoPagamento.setText("Ultimo Pagamento Efetuado: " +
                ControladorTransacoes.getInstance().getDataUltimoPagamento());

        JL_NumTotalAlugueis.setText("Numero Total de Alugueis: " +
                ControladorAlugueis.getInstance().numAlugueis());

        JL_NumTotalLogins.setText("Numero Total de Logins: " +
                ControladorLogin.getInstance().numLoginsCadastrados());

        JL_NumTotalPedidos.setText("Numero Total de Pedidos: " +
                ControladorPedidos.getInstance().numPedidos());

        JL_SaldoAtualCaixa.setText("Saldo Atual do Caixa: " +
                String.format("%.2f", ControladorTransacoes.getInstance().caixa()));


        preencheCBox();

        sis.salvarDados();
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new InterfaceAdmin().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton JB_CancelarAluguel;
    private javax.swing.JButton JB_Desloga;
    private javax.swing.JButton JB_EfetuaPagamento;
    private javax.swing.JButton JB_EfetuarPedido;
    private javax.swing.JButton JB_ExcluirPedido;
    private javax.swing.JButton JB_InfoLogin;
    private javax.swing.JButton JB_ListaAlugueis;
    private javax.swing.JButton JB_ListaPedidos;
    private javax.swing.JButton JB_ListaTransacoes;
    private javax.swing.JButton JB_ListaTransacoesMensais;
    private javax.swing.JButton JB_MenuClientes;
    private javax.swing.JButton JB_MenuFuncionarios;
    private javax.swing.JButton JB_MenuImoveis;
    private javax.swing.JButton JB_SalvarSalario;
    private javax.swing.JButton JB_VerFolhaDePagamento;
    private javax.swing.JButton JB_VerInfoAluguel;
    private javax.swing.JButton JB_VerInfoPedido;
    private javax.swing.JComboBox JCB_Alugueis;
    private javax.swing.JComboBox JCB_Logins;
    private javax.swing.JComboBox JCB_Pedidos;
    private javax.swing.JLabel JL_DataUltimoPagamento;
    private javax.swing.JLabel JL_NumTotalAlugueis;
    private javax.swing.JLabel JL_NumTotalLogins;
    private javax.swing.JLabel JL_NumTotalPedidos;
    private javax.swing.JLabel JL_Pagamento;
    private javax.swing.JLabel JL_SaldoAtualCaixa;
    private javax.swing.JTextField JTF_Comissao;
    private javax.swing.JTextField JTF_Salario;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

}
